// pages/ad/ad.js
Page({
  data: {
    ad: '../../static/images/ad.jpg',
    num: 3, // 改名为更语义化的countdown
    timer: null // 初始化为null更规范
  },

  onLoad(options) {
    this.jump()
  },

  jump() {
    this.data.timer = setInterval(() => {
      const count = this.data.num - 1
      this.setData({
        num: count
      })

      if (count <= 0) {
        // this.clearTimer()
        wx.switchTab({
          url: '/pages/index/index'
        })
      }
    }, 1000)
  },

  clearTimer() {
    clearInterval(this.data.timer)
  },
  go() {
    // this.clearTimer()
    wx.switchTab({
      url: '/pages/index/index'
    })
  },
  onUnload() {
    this.clearTimer()
  },
})